package com.my.kq.controller;


import com.my.kq.entity.Department;
import com.my.kq.entity.Employee;
import com.my.kq.entity.Position;
import com.my.kq.service.DepartmentService;
import com.my.kq.service.EmployeeService;
import com.my.kq.service.PositionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/EmployUpdate")
//欲修改
public class EmployUpdate extends HttpServlet {
    private com.my.kq.service.EmployeeService EmployeeService=new EmployeeService();
    private PositionService positionService=new PositionService();
    private com.my.kq.service.DepartmentService DepartmentService=new DepartmentService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        try {
            req.setCharacterEncoding("utf-8");
            resp.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
            HttpSession session = req.getSession();
            Employee cook =(Employee) session.getAttribute("cook");
            Integer id = cook.getId();
            Employee yee= EmployeeService.Empcx(id);
            session.setAttribute("employee",yee);
            //查询职称
            Integer number = yee.getPosition_number();
            Position post= positionService.select(number);
            session.setAttribute("posi",post);
            //查询部门
            Integer zcnumbr = yee.getDepartment_number();
            Department dep= DepartmentService.Demselect(zcnumbr);
            session.setAttribute("dep",dep);
//        HttpSession session = req.getSession();
//        Employee emp = (Employee)session.getAttribute("employee");
//        Position posi = (Position)session.getAttribute("posi");
//        Department dep = (Department)session.getAttribute("dep");
            req.getRequestDispatcher("jsp/admin/employee_update.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
